// pages/StudyCardList/StudyCardList.js
let app = getApp();
const httpUtils = require('../../utils/httpUtils.js');
let tool = require('../../utils/tool.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showSearchResult: false,
    page: 1,
    mData: []
  },
  getData: function () {

    let that = this
    that.setData({
      page: this.data.page
    });
    wx.showLoading({
      title: '正在加载',
      mask: true
    })
    httpUtils.studentcardlist({
      access_token: app.globalData.$TOKEN,
    }).then((res) => {
      wx.hideLoading()
      if (that.data.page == 1) {
        app.globalData.userDetail.doubleminus_type = res.data.doubleminus_type
        that.data.mData.push(...res.data);
      } else {
        that.data.mData.push(...res.data);
      }
      that.data.page = that.data.page + 1;
      that.setData({
        mData: that.data.mData,
        page: that.data.page
      });
      console.log("that.data.mData.length:" + that.data.mData.length);
      if (that.data.mData.length >= res.data.total) {
        that.setData({
          showSearchResult: false
        })
      } else {
        console.log("showSearchResult:" + that.data.showSearchResult);
        that.setData({
          showSearchResult: true
        })
      }

    });

  },
  lookdetail: function (e) {
    var id = e.currentTarget.dataset['id'];
    wx.navigateTo({
      url: '/pages/studyCardDetail/studyCardDetail?id=' + id,
    })
  },
  gorenew: function (e) {
    var item = e.currentTarget.dataset['id'];
    var address = item.district[0].province + item.district[0].city + item.district[0].area
    wx.navigateTo({
      url: '/pages/StudyCardRenew/StudyCardRenew?id=' + item.id + "&amount=" + item.amount + "&address=" + address + "&name=" + item.product_title,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // if (this.data.showSearchResult == true) {
    //   console.log("11onReachBottom" + this.data.showSearchResult + this.data.page)
    //   this.getData();
    // }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})